<html>
<head><meta http-equiv="content-type" content="text/html; charset=UTF-8"></head>
<body>
<?
include("jaro.php");
set_time_limit(1200);
mysql_connect("dev.ivaldi.nl", "root", "w8woord-ivaldi") or die(mysql_error());
mysql_select_db("publications") or die(mysql_error());
$query = mysql_query("SELECT name, id FROM authors_dn");

$i = 0;
while($res = mysql_fetch_array($query)){

	$userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
	$target_url = "http://dblp.uni-trier.de/search/author?xauthor=".urlencode($res['name']);

	$ch = curl_init();
	curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
	curl_setopt($ch, CURLOPT_URL,$target_url);
	curl_setopt($ch, CURLOPT_FAILONERROR, true);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
	curl_setopt($ch, CURLOPT_AUTOREFERER, true);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	$html = curl_exec($ch);
	$dom = new DOMDocument();
	@$dom->loadHTML($html);

	$authors = $dom->getElementsByTagName("author");
	//echo '<b>'.$authors->length.' resultaten!</b><br/>';
	
	//1436 matches with LIKE == 1
	//322 matches with LIKE == 0 (what can we do with name algorithms?)
	//220 matches with LIKE 1 < x < 4
	//177 matches with LIKE > 3
	if($authors->length > 0){
		
		foreach( $authors as $author ){
			$name = $authors->item($i)->nodeValue;			
			echo $name. ' - <a href="http://dblp.l3s.de/d2r/page/authors/'.str_replace("+","_",urlencode($name)).'">Dereference DBLP</a>';
			echo "Levenshtein: " . levenshtein($name,$res['name']) ."-";
			echo "Jaro-Winkler: " . JaroWinkler($name,$res['name']) ."<br/>";
			$i++;
			break;
		}
		break;
	}
}

echo 'Totaal aantal matches 1 < x < 4 gevonden: '.$i;

?>